package com.hewep;

	
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

import com.hewep.kit.ConfigKit;
import com.hewep.view.AppPane;
import com.hewep.view.ConfigPane;

/**
 * 应用程序主类
 * @author Administrator
 */
public class Main extends Application {
	private Stage stage ;
	private MyServer myServer;
	@Override
	public void start(Stage primaryStage) {
		this.stage = primaryStage;
		try {
			stage.initStyle(StageStyle.TRANSPARENT);
			stage.setTitle("常用工具");
			this.route("app");
			stage.show();
			
		} catch(Exception e) {
			e.printStackTrace();
		}
	}
	
	@Override
	public void stop() throws Exception {
		// TODO Auto-generated method stub
		
		if (myServer != null) {
			myServer.stop();
		}
		super.stop();
	}

	public void startServer() {
		try {
			// 启动 jetty
			int port = ConfigKit.getInt("local_port", 80);
			int scanInterval = ConfigKit.getInt("scan_interval", 0);
			myServer = new MyServer("WebRoot", port, "/", scanInterval);
			myServer.start();

		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}

	}
	
	public Stage getStage(){
		return this.stage;
	}
	/**
	 * 前端路由配置
	 * @param routeName
	 */
	public void route(String routeName){
		AnchorPane root = null;
		
		if(routeName.equals("config")){
			root = new ConfigPane(this);
		}else if(routeName.equals("app")){
			root = new AppPane(this);
		}
		this.stage.setScene(new Scene(root));
		//this.stage.getScene().setRoot(root);
	}
	
	public static void main(String[] args) {
		// 启动客户端
		launch(args);
	}
}
